package com.manytory.torycoupon.data;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.content.SharedPreferences;

public class ToryCoupon_App extends Application{
	final private String ToryCoupon_SharedPreferences = "ToryCoupon_SharedPreferences";
	private static SharedPreferences.Editor PreEditor;
	
	final private static String ToryCoupon_Auth_State = "ToryCoupon_Auth_State";
	final private static String ToryCoupon_PushKey = "ToryCoupon_PushKey";
	final private static String ToryCoupon_Device_SerialNum = "ToryCoupon_Device_SerialNum";
	
	public static int nAuthState = 0;
	public static String strDeviceSerial = "";
	public static String strPushKey = "";
	
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		loadPreferences();
	}
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
	}

	@SuppressLint("WorldWriteableFiles")
	public void loadPreferences() {
		SharedPreferences Preferences = getSharedPreferences(ToryCoupon_SharedPreferences, Activity.MODE_WORLD_WRITEABLE);
		PreEditor = Preferences.edit();
		
		nAuthState = Preferences.getInt(ToryCoupon_Auth_State, 0);
		strDeviceSerial = Preferences.getString(ToryCoupon_Device_SerialNum, "");
		strPushKey = Preferences.getString(ToryCoupon_PushKey, "");
	}
	
	public void saveAuthStatePreferences(int devauthFlag) {
		nAuthState = devauthFlag;
		PreEditor.putInt(ToryCoupon_Auth_State, nAuthState);
		PreEditor.commit();
	}
	
	public void saveDeviceSerialPreferences(String strDevSerial) {
		strDeviceSerial = strDevSerial;
		PreEditor.putString(ToryCoupon_Device_SerialNum, strDevSerial);
		PreEditor.commit();
	}
	
	public void savePushKeyPreferences(String strkey) {
		strPushKey = strkey;
		PreEditor.putString(ToryCoupon_PushKey, strkey);
		PreEditor.commit();
	}
}
